//
//  HACPainter.h
//  HStockCharts
//
//  Created by Hotacool on 2018/9/14.
//

#import <QuartzCore/QuartzCore.h>
#import <Foundation/Foundation.h>

typedef UIBezierPath*(^GeneratePathBlock)(void);
typedef void(^CompletionBlock)(id _Nullable value, BOOL canceled);
@protocol HACPainterDelegate;
@protocol HACAsynchronousAble <NSObject>
@property (nonatomic, assign) BOOL displaysAsynchronously;
@property (nonatomic, weak) id<HACPainterDelegate> painterDelegate;

+ (instancetype)painterLayer;
- (instancetype)initWithDelegate:(id<HACPainterDelegate>)delegate;
- (void)supperDisplay ;
@end

@protocol HACPainterDelegate <NSObject>
+ (dispatch_queue_t)displayQueue;
+ (dispatch_queue_t)serialOperationQueue;

- (void)addCompletionBlock:(CompletionBlock)block ;
- (void)displayLayer:(CALayer<HACAsynchronousAble> *)layer asynchronously:(BOOL)asynchronously;
@end

@interface HACPainter : CALayer <HACAsynchronousAble>
@property (nonatomic, assign) BOOL displaysAsynchronously;
@property (nonatomic, weak) id<HACPainterDelegate> painterDelegate;

@end

@interface HACPathPainter : CAShapeLayer <HACAsynchronousAble>
@property (nonatomic, assign) BOOL displaysAsynchronously;
@property (nonatomic, weak) id<HACPainterDelegate> painterDelegate;
@property (nonatomic, assign) BOOL generatePathAsynchronously;//异步生成path。低端机上的频繁刷新可能出现视觉上闪动问题

- (void)generateSubPath:(GeneratePathBlock)block;

- (void)paintInLayer:(CALayer*)superLayer;

- (HACPathPainter*)clearContents ;
@end

@interface HACTextPainter : CATextLayer <HACAsynchronousAble>
@property (nonatomic, assign) BOOL displaysAsynchronously;
@property (nonatomic, weak) id<HACPainterDelegate> painterDelegate;

- (void)paintInLayer:(CALayer*)superLayer;
@end

@interface HACGradientPainter : CAGradientLayer <HACAsynchronousAble>
@property (nonatomic, assign) BOOL displaysAsynchronously;
@property (nonatomic, weak) id<HACPainterDelegate> painterDelegate;

@end

@interface HACGradienPathPainter : HACPainter
@property (nullable, nonatomic, copy) NSArray *colors;
@property (nonatomic, assign) CGRect paintRect;

- (void)generatePath:(GeneratePathBlock)block;
- (void)paintInLayer:(CALayer*)superLayer;
- (HACGradienPathPainter*)clearContents;
@end
